class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        //x - 97 + 1 = 24;
        vector<int> ret;
        char hash1[26];
        for(int i = 0; i < p.size(); i++)
        {
            hash1[p[i] - 97]++;
        }

        char hash2[26]; //right - 0 = p.size()
        for(int left = 0, right = 0; right < s.size(); right++)
        {
            hash2[s[right] - 97]++;
            if(right - left + 1 == p.size())
            {
                //判断两个hash中的内容是否一样
                int flag = 1;
                for(int i = 0; i < 24; i++)
                {
                    if(hash1[i] != hash2[i])
                    {
                        flag = 0;
                        break;
                    }
                }
                if(flag)
                {
                    ret.push_back(left);
                }
                hash2[s[left++] - 97]--;
            }
            else if(right - left + 1 < p.size())
            {
                continue;
            }
            else if(right - left + 1 > p.size())
            {
                hash2[s[left++] - 97]--;
            }
        }
        return ret;
    }
};